<template>
  <div>
    <!-- <r-search ref="search" :searchData="searchData" :searchForm="searchForm" :searchHandle="searchHandle"
      :inline="true" />

    <r-table :isPagination="true" :isHandle="true" :tableData="tableData" :tableCols="tableCols" :tablePage="pagination"
      :loading="tableLoading" :tableHandles="tableHandles" :isSelection="false" @refresh="page()" />

    <r-form :formRules="formRules" :formHandle="formHandle" :formData="formData" :formCols="formCols" ref="elForm"
      labelWidth="100px" dialogWidth="500px" :isHandle="true" /> -->
    暂未开放，如需要帮助请咨询厂家
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      searchData: {
        orderNo: "",
        sn: "",
        phone: "",
        beginTime: "",
        endTime: "",
        newBatteryNo: ""
      },
      searchForm: [
        {
          type: "input",
          placeholder: "Order Nnumber",
          prop: "orderNo",
          width: 200
        },
        { type: "input", placeholder: "Device Number", prop: "sn", width: 200 },
        {
          type: "date",
          placeholder: "Start Date",
          prop: "beginTime",
          width: 180,
          change: val => {
            this.searchData.beginTime = val;
          }
        },
        {
          type: "date",
          placeholder: "End Date",
          prop: "endTime",
          width: 180,
          change: val => {
            this.searchData.endTime = val;
          }
        },
        { type: "input", placeholder: "User phone", prop: "phone", width: 200 },
        {
          type: "input",
          placeholder: "New Battery Number",
          prop: "newBatteryNo",
          width: 260
        }
      ],
      searchHandle: [
        {
          type: "primary",
          label: "Search",
          plain: true,
          handle: e => this.getData()
        }
        // {type:'primary',label:'Reset', handle: e => this.elFormSubmit(),}
      ],
      tableLoading: false,
      tableData: [{}],
      tableCols: [
        { label: "Order Nnumber", prop: "orderNo" },
        // { label: "Order Type", prop: "nickName",  },
        { label: "Package Information", prop: "mealName" },
        { label: "New Battery Number", prop: "newBatteryNo" },
        { label: "Old Battery Number", prop: "oldBatteryNo" },
        { label: "Device Number", prop: "deviceNo" },
        { label: "用户信息", prop: "userName" },
        { label: "User phone", prop: "phone" },
        // { label: "订单Money", prop: "isVip_des",  },
        // { label: "PaymentMoney", prop: "isVip_des",  },
        {
          label: "订单Status",
          prop: "status",
          // type: 'html',
          // html: (row) => {
          //   let html = '<p>' +
          //     (row.status == 0 ? "进行中" :
          //       row.status == 1 ? "Completed" :
          //         row.status == 2 ? "Overdue" :
          //           row.status == 3 ? "订单Already Cancel" : "--")
          //     + '</p>'
          //   return html
          // },
          itemClass: e => (e.status == 3 ? "danger" : ""),
          formatter: e =>
            e.status == 0
              ? "进行中"
              : e.status == 1
              ? "Completed"
              : e.status == 2
              ? "Overdue"
              : e.status == 3
              ? "订单Already Cancel"
              : "--"
        },
        {
          label: "BatteryStatus",
          prop: "btStatus",
          type: "html",
          html: row => {
            let html =
              "<p>" +
              (row.btStatus == 0
                ? "租借中"
                : row.btStatus == 1
                ? "已Return"
                : row.btStatus == 2
                ? "Not Returned"
                : row.btStatus == 3
                ? "非法Battery"
                : row.btStatus == 4
                ? "Battery不匹配"
                : "--") +
              "</p>";
            return html;
          }
        },
        {
          label: "Business Type",
          prop: "openType",
          formatter: e =>
            e.openType == 1
              ? "租Battery"
              : e.openType == 2
              ? "Battery Swap"
              : e.openType == 3
              ? "管理员开门"
              : "--"
        },
        {
          label: "Cabinet Opening Result",
          prop: "openResult",
          itemClass: e => (e.openResult == 0 ? "danger" : "success"),
          formatter: e =>
            e.openResult == 0 ? "Failure" : e.openResult == 1 ? "Success" : "--"
        },
        { label: "Start Time", prop: "ctime" },
        { label: "Completion Time", prop: "ftime" },

        {
          label: "Operations",
          type: "button",
          width: 260,
          btnList: [
            {
              label: "End Order",
              type: "primary",
              plain: true,
              size: "small",
              handle: row => {
                this.$confirm("确定要End Order吗?", "Hint", {
                  confirmButtonText: "Confirm",
                  cancelButtonText: "Cancel",
                  type: "warning"
                })
                  .then(async () => {
                    const res = await this.apis.orderExchange_endOrder({
                      id: row.id
                    });
                    this.$message({
                      type: "success",
                      message: "DeleteSuccess!"
                    });
                  })
                  .catch(() => {});
              }
            },
            // {
            //   label: 'Order Details',
            //   type: 'text',
            //   handle: (row) =>{}
            // },
            {
              label: "更Battery Swap",
              type: "primary",
              plain: true,
              size: "small",
              handle: row => {
                this.formData.id = row.id;
                this.elFormVisible("更Battery Swap");
              }
            },
            {
              label: "Return",
              type: "danger",
              plain: true,
              size: "small",
              isShow: row => {
                if (row.btStatus == 2) {
                  return true;
                } else {
                  return false;
                }
              },
              handle: row => {
                this.$confirm("确定已Return吗?", "Hint", {
                  confirmButtonText: "Confirm",
                  cancelButtonText: "Cancel",
                  type: "warning"
                })
                  .then(async () => {
                    const res = await this.apis.orderExchange_giveBack({
                      id: row.id
                    });
                    this.$message({
                      type: "success",
                      message: "Operations Success!"
                    });
                    this.getData();
                  })
                  .catch(() => {});
              }
            }
          ]
        }
      ],
      tableHandles: [
        {
          label: "Battery Swap OrdersExport",
          type: "primary",
          icon: "el-icon-download",
          titles:
            "可以根据订单编号、Device Number、Phone、Start Time、结束时间筛选出订单再Export，也可以不选，直接ExportWhole订单",
          plain: true,
          loading: false,
          handle: async e => {
            const res = await this.apis.orderExchangeExport(this.searchData);
            // console.log(333, this.searchData, res.msg);
            this.$message({
              type: res.code == 200 ? "success" : "error",
              message: res.code == 200 ? "success" : "error"
            });
            location.href = process.env.VUE_APP_URL + res.msg;
          }
        }
      ],
      pagination: { limit: 10, offset: 1, total: 1 },

      formData: {
        id: "",
        batteryNo: ""
      },
      formCols: [
        {
          type: "input",
          label: "更Battery Swap",
          placeholder: "Please Input更换后的Battery Number",
          width: 350,
          prop: "batteryNo",
          rmblock: true,
          remark: ""
        }
      ],
      formRules: {
        batteryNo: [
          { required: true, message: "Please Enter", trigger: "blur" }
        ]
      },
      formHandle: [
        {
          label: "Cancel",
          handle: e => this.elFormVisible()
        },
        {
          label: "Confirm",
          type: "success",
          handle: e => {
            this.$refs.elForm.$refs.ruleForm.validate(async valid => {
              if (valid) {
                const res = await this.apis.orderExchange_replace(
                  this.formData
                );
                this.$message({
                  message: "OperationsSuccess！",
                  type: "success"
                });
                this.getData();
                this.elFormVisible();
              }
            });
          }
        }
      ]
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    userDetailsCall() {
      this.userDetailsData.show = false;
    },
    async usersys_updata(row) {
      var res = await this.apis.usersys_updata({
        id: row.id,
        state: row.state == 34 ? 35 : 34
      });
      this.getData();
    },
    async getData() {
      var res = await this.apis.orderExchange_list({
        orderNo: this.searchData.orderNo,
        sn: this.searchData.sn,
        phone: this.searchData.phone,
        newBatteryNo: this.searchData.newBatteryNo,
        beginTime: this.searchData.beginTime,
        endTime: this.searchData.endTime,
        pageNum: this.pagination.offset,
        pageSize: this.pagination.limit
      });
      // console.log(res);
      var list = res.rows || [];

      this.tableData = list;
      this.pagination.total = res.total;
    },
    page() {
      this.getData();
    }
  }
};
</script>

<style scoped lang="scss"></style>
